package handler

import (
	"net/http"

	"github.com/gin-gonic/gin"

	"plastic-company/internal/model"
)

// GetContacts 获取所有客户咨询
func GetContacts(c *gin.Context) {
	var contacts []model.Contact
	result := db.Find(&contacts)

	if result.Error != nil {
		c.JSON(http.StatusInternalServerError, model.APIResponse{
			Success: false,
			Message: "获取客户咨询失败",
		})
		return
	}

	c.JSON(http.StatusOK, model.APIResponse{
		Success: true,
		Data:    contacts,
	})
}

// DeleteContact 删除客户咨询
func DeleteContact(c *gin.Context) {
	id := c.Param("id")

	result := db.Delete(&model.Contact{}, id)
	if result.Error != nil {
		c.JSON(http.StatusInternalServerError, model.APIResponse{
			Success: false,
			Message: "删除客户咨询失败",
		})
		return
	}

	c.JSON(http.StatusOK, model.APIResponse{
		Success: true,
		Message: "删除客户咨询成功",
	})
}